package modelLayer;

import java.util.ArrayList;
import java.util.List;

/**
 * This class is a modelLayer class of the MSAS system. It holds
 * information on a single subject. True to our domain model, the subject
 * class has field visibility to Teacher. The Class class is itself
 * referenced in TeachingBlock.
 * 
 * @author Danny M�lgaard, Anna Kelemen, Jakob Korsgaard
 * 		   
 * @version 1.3.1
 * 					1.3.1: 		Added more extensive documentation. Verified that
 * 								information contained in the Design Class Diagram,
 * 								is in accordance with the information contained in this
 * 								class.
 * 					1.3.2: 		toString() adjusted
 */
public class Subject {

	private String name;
    private String description;
	private int id;
	private List<Teacher> teachers = new ArrayList<Teacher>();
	
	/**
	 * Instantiating a Subject object, taking no parameters, altering no variables.
	 */
	public Subject() {
	}
	
	/**
	 * Instantiating a Subject object, taking the following parameters:
	 * 
	 * @param	id		int			id of the subject, as allocated in the database.
	 */
	public Subject(int id) {
		
		this.setId(id);
		
	}
	
	/**
	 * Instantiating a Subject object, taking the following parameters:
	 * 
	 * @param	name		String		name of the subject.
	 * @param	description	String		subject description.
	 * @param	t			Teacher		the Teacher object to be referenced by
	 *									the subject.
	 */
	public Subject(String name, String description) {
		
		this.setName(name);
		this.setDescription(description);
		//this.setTeacher(t);
		
	}
	
	/**
	 * Instantiating a Subject object, taking the following parameters:
	 * 
	 * @param	name		String		name of the subject.
	 * @param	description	String		subject description.
	 * @param	t			Teacher		the Teacher object to be referenced by
	 *									the subject.
	 * @param	id			int			id of the subject, as allocated in the database.
	 */
	public Subject(int id, String name, String description) {
		
		this.setName(name);
		this.setDescription(description);
		//this.setTeacher(t);
		this.setId(id);
		
	}
	
	public void addTeacher(Teacher t){
		if (t != null && !this.teachers.contains(t)){
			this.teachers.add(t);
		}
	}
	
	/**
	 * Assigns a parameter to the description field.
	 * 
	 * @param 	description		String	the description of the subject.					
	 */
	public void setDescription(String description) {

		this.description = description;

	}
	
	/**
	 * Assigns a parameter to the id field, defining the, by the database allocated, id
	 * of the subject.
	 * 
	 * @param 	id			int		the id the subject in the database.					
	 */
	public void setId(int id) {

		this.id = id;

	}
	
	/**
	 * Assigns a parameter to the t field, referencing a Teacher object.
	 * 
	 * @param 	t		Teacher		the Teacher object to be referenced by
	 * 								the subject.					
	 */
	public void setTeachers(List<Teacher> teachers) {

		this.teachers = teachers;

	}
	
	/**
	 * Assigns a parameter to the name field, defining the uniquely associated subject name.
	 * 
	 * @param 	name		String	the name of the subject.					
	 */
	public void setName(String name) {

		this.name = name;

	}
	
	/**
	 * Returns the description of the subject.
	 * 
	 * @return 	description		String	the description of the subject.
	 */
	public String getDescription() {
		
		return this.description;

	}
	
	/**
	 * Returns the id of the subject.
	 * 
	 * @return 	id		int		the id of the subject.
	 */
	public int getId() {

		return this.id;
		
	}

	/**
	 * Returns the Teacher object associated with the Subject object.
	 * 
	 * @return 	t			Teacher		the Teacher object referenced by the Subject object
	 */
	public List<Teacher> getTeachers() {

		return this.teachers;

	}
	
	/**
	 * Returns the name of the subject.
	 * 
	 * @return 	name		String	the name of the subject.
	 */
	public String getName() {

		return this.name;

	}

	/**
	 * Overrides the object's default toString() method. Returns the object as a String
	 * literal to the caller.
	 * 
	 * return				String	the Subject object represented as a String object.
	 */
	@Override
	public String toString() {

		//return "Subject [name=" + name + ", ID =" + id + "]";
		return this.name;
	}	
	
	/**
	 * Implements a check, to verify if an object is the same
	 * as this object. Uses class identification number to
	 * verify.
	 * 
	 * @param	o		Object	any object type.
	 * @return	true			if: 
	 * 							object is not null, and
	 * 							object is of type Subject, and
	 * 							object id field matches this objects id field.
	 * @return	false			if:
	 * 							object is null, or
	 * 							object is not an instance of Subject, or
	 * 							object id field doesn't match this objects id field.
	 */
	@Override
	public boolean equals(Object o) {
		
		if (o != null && (o instanceof Subject)){
			Subject s = (Subject) o;
			if (this.getName() != null && this.getName().equals(s.getName())) {
				return true;
			}
		}
			
		return false;

	}
	
}
